﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;

/// <summary>
/// 平均工资表dao 的摘要说明
/// </summary>
public class 平均工资表dao
{
	public 平均工资表dao()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    #region  成员方法
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from 平均工资表");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

            return DataBase.runExecuteScalar(strSql.ToString(), parameters) >= 1;
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(平均工资表 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into 平均工资表(");
			strSql.Append("year,salary,flag)");
			strSql.Append(" values (");
			strSql.Append("@year,@salary,@flag)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@year", SqlDbType.Int,4),
					new SqlParameter("@salary", SqlDbType.Float,8),
					new SqlParameter("@flag", SqlDbType.Int,4)};
			parameters[0].Value = model.year;
			parameters[1].Value = model.salary;
			parameters[2].Value = model.flag;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public int Update(平均工资表 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update 平均工资表 set ");
			strSql.Append("year=@year,");
			strSql.Append("salary=@salary,");
			strSql.Append("flag=@flag");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@year", SqlDbType.Int,4),
					new SqlParameter("@salary", SqlDbType.Float,8),
					new SqlParameter("@flag", SqlDbType.Int,4)};
			parameters[0].Value = model.id;
			parameters[1].Value = model.year;
			parameters[2].Value = model.salary;
			parameters[3].Value = model.flag;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public int Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from 平均工资表 ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

            return DataBase.runExecute(strSql.ToString(), parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public 平均工资表 GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,year,salary,flag from 平均工资表 ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = id;

			平均工资表 model=new 平均工资表();
            DataSet ds = DataBase.runProcGetSet(strSql.ToString(), parameters);

			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["year"].ToString()!="")
				{
					model.year=int.Parse(ds.Tables[0].Rows[0]["year"].ToString());
				}
				if(ds.Tables[0].Rows[0]["salary"].ToString()!="")
				{
					model.salary=decimal.Parse(ds.Tables[0].Rows[0]["salary"].ToString());
				}
				if(ds.Tables[0].Rows[0]["flag"].ToString()!="")
				{
					model.flag=int.Parse(ds.Tables[0].Rows[0]["flag"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,year,salary,flag ");
			strSql.Append(" FROM 平均工资表 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            return DataBase.runProcGetSet(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,year,salary,flag ");
			strSql.Append(" FROM 平均工资表 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
            return DataBase.runProcGetSet(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "平均工资表";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
}
